home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / CUGUK / PC_LIBS / C045.ZIP / BTREE.ARC / BTREEINC.C < prev    next >
C/C++ Source or Header  |  1989-02-08  |  20KB  |  565 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6. #include <dos.h>
  7.  
  8. #include "cstruct.h"
  9. #include "datatype.h"
  10. #include "ctrlkey.h"
  11. #include "btutil.h"
  12. #include "access.h"
  13. #include "addkey.h"
  14. #include "delkey.h"
  15. #include "getkey.h"
  16. #include "globals.h"
  17.  
  18. #include "names.h"
  19.  
  20. typedef enum {dolist, dodelete} actiontype;
  21. typedef enum {cpage, npage} pagetype;
  22.  
  23. static void listkey(indexfile * nxfp);
  24. static void add(void), find(void), linecust(void), inputcust(void);
  25. static void outcust(custrec * custp);
  26. static char * keyfromname(char * lname, char * fname);
  27. static void listkey(indexfile * nxfp);
  28. static void unsorted(actiontype action);
  29.  
  30. static  char    sbuf[64], ccode[16], keyn[26];
  31. static  custrec cust , *csp  = &cust;
  32. static  custrec cust1, *csp1 = &cust1;
  33.  
  34. void update_record_count(void)
  35. {
  36.     gotoxy(60,2);
  37.     printf("%5d active records", usedrecs(datfp));
  38. }
  39.  
  40. static void outpage(tapage * pgptr, pagetype page)
  41. {
  42.     char tmpstr[10];
  43.     int  n;
  44.  
  45.     tmpstr[9] = '\0';
  46.     n = page == cpage ? 0 : 9;
  47.  
  48.     gotoxy(1,4+n);
  49.     printf("Items_On_Page: %4d, BackwdRef: %4d, Page No. %4d",
  50.                                pgptr->itemsonpage, pgptr->bckwpageref,
  51.                                ((tapagerec *) pgptr)->pageref);
  52.  
  53.     switch (pgptr->itemsonpage) {
  54.         case 16: strncpy(tmpstr, pgptr->itemarray[15].key, 9);
  55.                  gotoxy(71, 9+n); printf("%-9s", tmpstr);
  56.                  gotoxy(71,10+n); printf("%5d", pgptr->itemarray[15].dataref);
  57.                  gotoxy(76,10+n); printf("%4d", pgptr->itemarray[15].pageref);
  58.         case 15: strncpy(tmpstr, pgptr->itemarray[14].key, 9);
  59.                  gotoxy(61, 9+n); printf("%-9s", tmpstr);
  60.                  gotoxy(61,10+n); printf("%5d", pgptr->itemarray[14].dataref);
  61.                  gotoxy(66,10+n); printf("%4d", pgptr->itemarray[14].pageref);
  62.         case 14: strncpy(tmpstr, pgptr->itemarray[13].key, 9);
  63.                  gotoxy(51, 9+n); printf("%-9s", tmpstr);
  64.                  gotoxy(51,10+n); printf("%5d", pgptr->itemarray[13].dataref);
  65.                  gotoxy(56,10+n); printf("%4d", pgptr->itemarray[13].pageref);
  66.         case 13: strncpy(tmpstr, pgptr->itemarray[12].key, 9);
  67.                  gotoxy(41, 9+n); printf("%-9s", tmpstr);
  68.                  gotoxy(41,10+n); printf("%5d", pgptr->itemarray[12].dataref);
  69.                  gotoxy(46,10+n); printf("%4d", pgptr->itemarray[12].pageref);
  70.         case 12: strncpy(tmpstr, pgptr->itemarray[11].key, 9);
  71.                  gotoxy(31, 9+n); printf("%-9s", tmpstr);
  72.                  gotoxy(31,10+n); printf("%5d", pgptr->itemarray[11].dataref);
  73.                  gotoxy(36,10+n); printf("%4d", pgptr->itemarray[11].pageref);
  74.         case 11: strncpy(tmpstr, pgptr->itemarray[10].key, 9);
  75.                  gotoxy(21, 9+n); printf("%-9s", tmpstr);
  76.                  gotoxy(21,10+n); printf("%5d", pgptr->itemarray[10].dataref);
  77.                  gotoxy(26,10+n); printf("%4d", pgptr->itemarray[10].pageref);
  78.         case 10: strncpy(tmpstr, pgptr->itemarray[ 9].key, 9);
  79.                  gotoxy(11, 9+n); printf("%-9s", tmpstr);
  80.                  gotoxy(11,10+n); printf("%5d", pgptr->itemarray[ 9].dataref);
  81.                  gotoxy(16,10+n); printf("%4d", pgptr->itemarray[ 9].pageref);
  82.         case  9: strncpy(tmpstr, pgptr->itemarray[ 8].key, 9);
  83.                  gotoxy( 1, 9+n); printf("%-9s", tmpstr);
  84.                  gotoxy( 1,10+n); printf("%5d", pgptr->itemarray[ 8].dataref);
  85.                  gotoxy( 6,10+n); printf("%4d", pgptr->itemarray[ 8].pageref);
  86.         case  8: strncpy(tmpstr, pgptr->itemarray[7].key, 9);
  87.                  gotoxy(71,6+n); printf("%-9s", tmpstr);
  88.                  gotoxy(71,7+n); printf("%5d", pgptr->itemarray[7].dataref);
  89.                  gotoxy(76,7+n); printf("%4d", pgptr->itemarray[7].pageref);
  90.         case  7: strncpy(tmpstr, pgptr->itemarray[6].key, 9);
  91.                  gotoxy(61,6+n); printf("%-9s", tmpstr);
  92.                  gotoxy(61,7+n); printf("%5d", pgptr->itemarray[6].dataref);
  93.                  gotoxy(66,7+n); printf("%4d", pgptr->itemarray[6].pageref);
  94.         case  6: strncpy(tmpstr, pgptr->itemarray[5].key, 9);
  95.                  gotoxy(51,6+n); printf("%-9s", tmpstr);
  96.                  gotoxy(51,7+n); printf("%5d", pgptr->itemarray[5].dataref);
  97.                  gotoxy(56,7+n); printf("%4d", pgptr->itemarray[5].pageref);
  98.         case  5: strncpy(tmpstr, pgptr->itemarray[4].key, 9);
  99.                  gotoxy(41,6+n); printf("%-9s", tmpstr);
  100.                  gotoxy(41,7+n); printf("%5d", pgptr->itemarray[4].dataref);
  101.                  gotoxy(46,7+n); printf("%4d", pgptr->itemarray[4].pageref);
  102.         case  4: strncpy(tmpstr, pgptr->itemarray[3].key, 9);
  103.                  gotoxy(31,6+n); printf("%-9s", tmpstr);
  104.                  gotoxy(31,7+n); printf("%5d", pgptr->itemarray[3].dataref);
  105.                  gotoxy(36,7+n); printf("%4d", pgptr->itemarray[3].pageref);
  106.         case  3: strncpy(tmpstr, pgptr->itemarray[2].key, 9);
  107.                  gotoxy(21,6+n); printf("%-9s", tmpstr);
  108.                  gotoxy(21,7+n); printf("%5d", pgptr->itemarray[2].dataref);
  109.                  gotoxy(26,7+n); printf("%4d", pgptr->itemarray[2].pageref);
  110.         case  2: strncpy(tmpstr, pgptr->itemarray[1].key, 9);
  111.                  gotoxy(11,6+n); printf("%-9s", tmpstr);
  112.                  gotoxy(11,7+n); printf("%5d", pgptr->itemarray[1].dataref);
  113.                  gotoxy(16,7+n); printf("%4d", pgptr->itemarray[1].pageref);
  114.         case  1: strncpy(tmpstr, pgptr->itemarray[0].key, 9);
  115.                  gotoxy( 1,6+n); printf("%-9s", tmpstr);
  116.                  gotoxy( 1,7+n); printf("%5d", pgptr->itemarray[0].dataref);
  117.                  gotoxy( 6,7+n); printf("%4d", pgptr->itemarray[0].pageref);
  118.                  break;
  119.     }
  120. }
  121.  
  122. static void clearcust(void)
  123. {
  124.     memset (csp, 0, sizeof(custrec));
  125. }
  126.  
  127. static void inputcust(void)
  128. {
  129.     static char  charset[] = "\x05\x09\x0d\x18\x1a";
  130.     int    h, tc;
  131.  
  132.     h = 1;
  133.     do {
  134.         switch (h) {
  135.             case 1 : tc = inputstr(csp->custcode, 15, 14, 5, charset);
  136.                      break;
  137.             case 2 : tc = inputstr(csp->entrydate, 8, 37, 5, charset);
  138.                      break;
  139.             case 3 : tc = inputstr(csp->firstname, 15, 14, 7, charset);
  140.                      break;
  141.             case 4 : tc = inputstr(csp->lastname, 30, 42, 7, charset);
  142.                      break;
  143.             case 5 : tc = inputstr(csp->company, 40, 14, 9, charset);
  144.                      break;
  145.             case 6 : tc = inputstr(csp->addr1, 40, 14, 10, charset);
  146.                      break;
  147.             case 7 : tc = inputstr(csp->addr2, 40, 14, 11, charset);
  148.                      break;
  149.             case 8 : tc = inputstr(csp->phone, 15, 14, 13, charset);
  150.                      break;
  151.             case 9 : tc = inputstr(csp->phoneext, 5, 42, 13, charset);
  152.                      break;
  153.             case 10 : tc = inputstr(csp->remarks1, 40, 14, 15, charset);
  154.                      break;
  155.             case 11 : tc = inputstr(csp->remarks2, 40, 14, 16, charset);
  156.                      break;
  157.             case 12 : tc = inputstr(csp->remarks3, 40, 14, 17, charset);
  158.                      break;
  159.         }
  160.         if ((tc == TAB) || (tc == RET) || (tc == CTLX))
  161.             h = h % 12 + 1;
  162.         else if (tc == CTLE)
  163.             h = (h + 10) % 12 + 1;
  164.     } while ( ((tc != RET) || (h != 1)) && (tc != CTLZ) );
  165. }
  166.  
  167. static void outcust(custrec * custptr)
  168. {
  169.     gotoxy(14,  5); printf("%-15s", custptr->custcode);
  170.     gotoxy(37,  5); printf("%s", custptr->entrydate); clreol();
  171.     gotoxy(14,  7); printf("%-15s", custptr->firstname);
  172.     gotoxy(42,  7); printf("%-15s", custptr->lastname); clreol();
  173.     gotoxy(14,  9); printf("%s", custptr->company); clreol();
  174.     gotoxy(14, 10); printf("%s", custptr->addr1); clreol();
  175.     gotoxy(14, 11); printf("%s", custptr->addr2); clreol();
  176.     gotoxy(14, 13); printf("%s", custptr->phone);
  177.     gotoxy(42, 13); printf("%s", custptr->phoneext); clreol();
  178.     gotoxy(14, 15); printf("%s", custptr->remarks1); clreol();
  179.     gotoxy(14, 16); printf("%s", custptr->remarks2); clreol();
  180.     gotoxy(14, 17); printf("%s", custptr->remarks3); clreol();
  181. }
  182.  
  183. static char * keyfromname(char * lastnm, char * firstnm)
  184. {
  185.     unsigned    n;
  186.  
  187.     memset(buffer, ' ', 25);
  188.     buffer[25] = '\0';
  189.     n = (strlen(lastnm) >= 15 ? 15 : strlen(lastnm));
  190.     memcpy(buffer, lastnm, n);
  191.     n = (strlen(firstnm) >= 10 ? 10 : strlen(firstnm));
  192.     memcpy (buffer+15, firstnm, n);
  193.  
  194.     return (strupr(buffer));
  195. }
  196.  
  197. static void linecust()
  198. {
  199.     gotoxy(1,24);
  200.     printf("Next entry: %8s %12s %15s", csp->custcode,
  201.                                  csp->firstname, csp->lastname);
  202. }
  203.  
  204. void create()
  205. {
  206.     int     i, datref;
  207.     char    ch;
  208.     tapage * addptr;
  209.  
  210.     clearcust();
  211.     while (TRUE) {
  212.         sprintf(csp->custcode, "%c%04d", random(4)+'A', random(5000));
  213.         strcpy(csp->entrydate, edates[random(MAXDATES)]);
  214.         strcpy(csp->firstname, fnames[random(MAXFNAMES)]);
  215.         strcpy(csp->lastname, lnames[random(MAXLNAMES)]);
  216.         strcpy(ccode, csp->custcode);
  217.  
  218.         if ((datref = findkey (cnxfp, ccode)) != NULL) {
  219.             linecust();
  220.             getrec(datfp, datref, (char *) csp1);
  221.             sprintf(sbuf, "Duped! Recno: %d is %s %s %s "
  222.                              "<Ret>: continue, 'q': quit",
  223.                     datref, csp1->custcode, csp1->firstname, csp1->lastname);
  224.             if ((ch = select (sbuf, "qQ\x0d")) != RET) break;
  225.         }
  226.         else {
  227.             linecust();
  228.             sprintf(sbuf, "Code unique - <Ret> to add, <sp> to skip, or 'q' to quit");
  229.             if ((ch = select(sbuf, "qQ\x20\x0d")) == RET) {
  230.                 datref = addrec(datfp, (char *) csp);
  231.                 addptr = addkey (cnxfp, datref, csp->custcode);
  232.                 clearwindow(1,4,80,20);
  233.                 outpage(addptr, cpage);
  234.                 strcpy (keyn, keyfromname(csp->lastname, csp->firstname));
  235.                 addptr = addkey (nnxfp, datref, keyn);
  236.                 outpage(addptr, npage);
  237.                 gotoxy(1, 2);
  238.                 printf("Entry added %8s %12s %15s   as record %d",
  239.                                     csp->custcode, csp->firstname,
  240.                                     csp->lastname, usedrecs(datfp));
  241.                 clreol();
  242.             }
  243.             else if (ch == 'q' || ch == 'Q')
  244.                 break;
  245.         }
  246.     }
  247.     clearwindow(1,2, 80,24);
  248. }
  249.  
  250. void reconstruct()
  251. {
  252.     int     ld, recno;
  253.     char    keyn[26];
  254.  
  255.     gotoxy(1,23);
  256.     printf("Reconstructing indices..."); clreol();
  257.  
  258.     /* first, set the datafile header aright, just in case.. */
  259.     datfp->numrecs = filelen(datfp);
  260.     datfp->firstfree = -1;
  261.     datfp->numberfree = 0;
  262.     memcpy(&tarecbuf, datfp, 12);
  263.     putrec(datfp, 0, (char *) &tarecbuf);
  264.  
  265.     ld = datfp->numrecs - 1;
  266.  
  267.     for (recno = 1; recno <= ld; recno++) {
  268.  
  269.         getrec(datfp, recno, (char *) csp);
  270.  
  271.         if (csp->custstatus == 0) { /* if not deleted and custcode
  272.                                        is unique, then add the keys */
  273.             if (addkey(cnxfp, recno, csp->custcode) != NULL) {
  274.                 strcpy(keyn, keyfromname (csp->lastname, csp->firstname));
  275.                 addkey(nnxfp, recno, keyn);
  276.             }
  277.         }
  278.         else
  279.             deleterec(datfp, recno);
  280.  
  281.         if (recno % 100 == 0) {
  282.             gotoxy(40,23);
  283.             printf("%4d indices reconstructed", recno);
  284.         }
  285.  
  286.     }
  287. }
  288.  
  289. static void add(void)
  290. {
  291.     int     datref;
  292.     char    ch;
  293.  
  294.     csp = &cust;
  295.     memset (csp, '\0', sizeof(custrec));
  296.     inputcust();
  297.     strcpy(ccode, csp->custcode);
  298.  
  299.     if ((datref = findkey (cnxfp, ccode)) != NULL) {
  300.         sprintf(sbuf, "Duplicate code at recno %d - <Sp> to continue", datref);
  301.         select (sbuf, " ");
  302.     }
  303.     else {
  304.         ch = select ("Customer code OK - Return to ADD, Sp-bar to cancel",
  305.                                                                "\x20\x0d");
  306.         if (ch == RET) {
  307.             datref = addrec(datfp, (char *) csp);
  308.             addkey (cnxfp, datref, csp->custcode);
  309.             strcpy (keyn, keyfromname(csp->lastname, csp->firstname));
  310.             addkey (nnxfp, datref, keyn);
  311.         }
  312.     }
  313. }
  314.  
  315. static void find(void)
  316. {
  317.     int     recno, caseno, codevalid;
  318.     char    ch, tc;
  319.     char    pnm[26], pcode[16], firstnm[16], lastnm[31];
  320.  
  321.     if (usedrecs(datfp) > 0) {
  322.         ccode[0] =  '\0';
  323.         do {
  324.             tc = inputstr(ccode, 15, 14, 5, "\x0d\x1a");
  325.             if (strlen(ccode) > 0)
  326.                 if ((recno = findkey(cnxfp, ccode)) != NULL) {
  327.                     getrec(datfp, recno, (char *) csp);
  328.                     outcust(csp);
  329.                 }
  330.                 else
  331.                     select("Customer code not found.. <Sp> to continue","\x20");
  332.         } while (ccode[0] != '\0' && recno == 0);
  333.  
  334.         if (ccode[0] == '\0') {
  335.             caseno = 1;
  336.             firstnm[0] = '\0';
  337.             lastnm[0]  = '\0';
  338.  
  339.             do {
  340.                 switch (caseno) {
  341.                     case 1 : tc = inputstr(firstnm, 15, 14, 7, "\x09\x0d\x1a");
  342.                              break;
  343.                     case 2 : tc = inputstr(lastnm, 30, 42, 7, "\x09\x0d\x1a");
  344.                              break;
  345.                 }
  346.                 if (tc == TAB || tc == RET)
  347.                     caseno = 3 - caseno;
  348.             } while (tc != CTLZ && (tc != RET || caseno != 1));
  349.  
  350.             strcpy (keyn, keyfromname(lastnm, firstnm));
  351.             if ((recno = searchkey(nnxfp, keyn)) == NULL)
  352.                 recno = prevkey(nnxfp, keyn);
  353.  
  354.             do {
  355.                 getrec(datfp, recno, (char *) csp);
  356.                 outcust(csp);
  357.                 ch = select("Find: N)ext, P)revious, Q)uit", "NnPpQq");
  358.  
  359.                 if ((ch = toupper(ch)) == 'N')
  360.                     recno = nextkey(nnxfp, keyn);
  361.                 else if (ch == 'P')
  362.                     recno = prevkey(nnxfp, keyn);
  363.  
  364.             } while (ch != 'Q');
  365.         }   /* if custcode[0] = '\0' */
  366.  
  367.         ch = select("Find: E)dit, D)elete, L)ist, Q)uit", "edlqEDLQ");
  368.         if ( (ch = toupper(ch)) == 'E' ) {
  369.             strcpy (pcode, csp->custcode);
  370.             strcpy (pnm, keyfromname(csp->lastname, csp->firstname));
  371.             do {
  372.                 clearwindow (1,23, 80,23);
  373.                 inputcust();
  374.            /*
  375.             *  After editing, if custcode hasn't changed, the code is considered
  376.             *  valid.  Otherwise, if the custcode does not already exist, it is
  377.             *  considered valid.
  378.             */
  379.                 if (strcmp (csp->custcode, pcode) == 0)
  380.                     codevalid = TRUE;
  381.                 else {
  382.                     strcpy (ccode, csp->custcode);
  383.                     if (findkey (cnxfp, ccode)) {
  384.                         codevalid = FALSE;
  385.                         select("Duplicate customer code .. Press space bar","\x20");
  386.                     }
  387.                     else {
  388.                         codevalid = TRUE;
  389.                         select("Customer code unique .. Press space bar","\x20");
  390.                     }
  391.                 }
  392.             } while (!codevalid);
  393.  
  394.             putrec (datfp, recno, (char *) csp);
  395.  
  396.             if (strcmp (csp->custcode, ccode) != 0) {
  397.                 deletekey (cnxfp, recno, pcode);
  398.                 addkey (cnxfp, recno, csp->custcode);
  399.             }
  400.  
  401.             strcpy (keyn, keyfromname (csp->lastname, csp->firstname));
  402.             if (strcmp (keyn, pnm) != 0) {
  403.                 deletekey (nnxfp, recno, pnm);
  404.                 addkey (nnxfp, recno, keyn);
  405.             }
  406.         }
  407.         else if (ch == 'D') {
  408.             deletekey (cnxfp, recno, csp->custcode);
  409.             strcpy (keyn, keyfromname (csp->lastname, csp->firstname));
  410.             deletekey (nnxfp, recno, keyn);
  411.             deleterec (datfp, recno);
  412.         }   /*  if (ch = toupper(ch)) == 'E'  */
  413.         else if (ch == 'L') {
  414.             clearwindow(1,2, 80,22);
  415.             recno = prevkey(nnxfp, keyn);
  416.             listkey(nnxfp);
  417.         }
  418.     }
  419.     else beep();
  420. }
  421.  
  422. void update(void)
  423. {
  424.     char    ch;
  425.  
  426.     ch = select("Update : A)dd, F)ind, Q)uit", "AaFfQq");
  427.     while ((ch = toupper(ch)) != 'Q') {
  428.         clearwindow(1,2, 80,22);
  429.         if (ch == 'F') {
  430.             outform();
  431.             find();
  432.         }
  433.         else if (ch == 'A') {
  434.             outform();
  435.             add();
  436.         }
  437.         update_record_count();
  438.         ch = select("Update : A)dd, F)ind, Q)uit", "AaFfQq");
  439.     }
  440.     clearform();
  441. }
  442.  
  443. static void listkey(indexfile * nxfp)
  444. {
  445.     int     recno, l;
  446.     char    ch;
  447.     char    name[36], startcode[26];
  448.  
  449.     if ((recno = nextkey(nxfp, ccode)) == NULL) {
  450.         beep();
  451.         return;
  452.     }
  453.  
  454.     getrec(datfp, recno, (char *) csp);
  455.     strcpy(startcode, csp->custcode);
  456.     l = 4;
  457.  
  458.     do {
  459.         if (kbhit())
  460.             if ((ch = getch()) == ESC)
  461.                 break;
  462.  
  463.         strcpy(name, csp->lastname);
  464.         if (strlen(csp->firstname)) {
  465.             strcat(name, ", ");
  466.             strcat(name, csp->firstname);
  467.         }
  468.         csp->company[30] = '\0';
  469.  
  470.         if (l == 22) {
  471.             ch = select("<Return> to continue, <ESC> to abort", "\x0d\x1b");
  472.             if (ch == ESC)
  473.                 return;
  474.             select("Press ESC to abort", "");
  475.             clearwindow(1, 4, 80, 21);
  476.             l = 4;
  477.         }
  478.         gotoxy(1, l++);
  479.         printf("%-10s %-35s %-30s", csp->custcode, name, csp->company);
  480.         recno = nextkey(nxfp, ccode);
  481.         getrec(datfp, recno, (char *) csp);
  482.  
  483.     } while (strcmp(startcode, csp->custcode) != 0);
  484.  
  485.     select("Press Return", "\x0d");
  486.  
  487. }
  488.  
  489. static void unsorted(actiontype action)
  490. {
  491.     int     recno, d, l, ld;
  492.     char    ch;
  493.     char    name[36];
  494.  
  495.     if ((ld = filelen(datfp) - 1) == 0) {
  496.         beep();
  497.         return;
  498.     }
  499.  
  500.     d = 0;
  501.     l = 4;
  502.  
  503.     while (TRUE) {
  504.  
  505.         recno = 0;
  506.         while ( recno == 0 && ++d <= ld ) {
  507.             getrec(datfp, d, (char *) csp);
  508.             recno = (csp->custstatus == 0) ? d : 0;
  509.         }
  510.  
  511.         if (recno == 0) break;
  512.  
  513.         strcpy(name, csp->lastname);
  514.         if (strlen(csp->firstname)) {
  515.             strcat(name, ", ");
  516.             strcat(name, csp->firstname);
  517.         }
  518.  
  519.         if (l == 22) {
  520.             update_record_count();
  521.             ch = select("<Return> to continue, <ESC> to abort","\x0d\x1b");
  522.             if (ch == ESC)
  523.                 return;
  524.             clearwindow(1, 4, 80, 21);
  525.             l = 4;
  526.         }
  527.  
  528.         gotoxy(1, l);
  529.         if (action == dodelete) {
  530.             deletekey(cnxfp, recno, csp->custcode);
  531.             strcpy(keyn, keyfromname(csp->lastname, csp->firstname));
  532.             deletekey(nnxfp, recno, keyn);
  533.             deleterec(datfp, recno);
  534.             printf("%-10s %-35s %-30s", csp->custcode, name, "deleted");
  535.         }
  536.         else
  537.             printf("%-10s %-35s %-30s", csp->custcode, name, csp->company);
  538.         l++;
  539.  
  540.     }
  541.     select("Press return", "\x0d");
  542. }
  543.  
  544. void list(void)
  545. {
  546.     char    ch;
  547.  
  548.     ch = select("Sort by : C)ode, N)ame, U)nsorted", "cnuCNU");
  549.  
  550.     if ((ch = toupper(ch)) == 'C') {
  551.         clearkey(cnxfp);
  552.         listkey(cnxfp);
  553.     }
  554.     else if (ch == 'N') {
  555.         clearkey(nnxfp);
  556.         listkey(nnxfp);
  557.     }
  558.     else
  559.         unsorted(dolist);
  560. }
  561.  
  562. void delete(void)
  563. {
  564.     unsorted(dodelete);
  565. }